<script setup>
import { ref, onMounted } from 'vue';

const currentOrgIndex = ref(0);
const orgCards = ref([]);

// 卡片数据
const organizations = [
  {
    id: '1',
    name: '互帮互助五人本',
    description: '百业成员互帮互助，齐心协力，共同拿下五人本！',
    host: '任何百业成员',
    time: '任何时间',
    location: '任何地点',
    image: 'https://www.yysls.cn/pc/gw/20220815175950/img/mhys/bz/17_33f9186.jpg?image_process=format,jpg'
  },
  {
    id: 'shaolin',
    name: '互帮互助十人本',
    description: '百业成员互帮互助，齐心协力，共同拿下双十人本（百业本+普通本）！',
    host: '任何百业成员',
    time: '一般周一晚上9.30',
    location: '任何地点',
    image: 'https://www.yysls.cn/pc/gw/20220815175950/img/mhys/bz/18_bd1a5dc.jpg?image_process=format,jpg'
  },
];

onMounted(() => {
  // 获取所有组织卡片元素
  orgCards.value = document.querySelectorAll('.org-card-img');
  updateOrgCarousel();
});

const updateOrgCarousel = () => {
  // 简单实现，只显示当前索引的卡片
  if (orgCards.value.length > 0) {
    orgCards.value.forEach((card, idx) => {
      card.style.display = (idx === currentOrgIndex.value) ? 'flex' : 'none';
    });
  }
};

const prevOrgCard = () => {
  currentOrgIndex.value = (currentOrgIndex.value - 1 + organizations.length) % organizations.length;
  updateOrgCarousel();
};

const nextOrgCard = () => {
  currentOrgIndex.value = (currentOrgIndex.value + 1) % organizations.length;
  updateOrgCarousel();
};
</script>

<template>
  <div id="toOrganizations" class="video-section-spacer">
    <div class="section-header">
      <h2 class="section-title">百业活动</h2>
      <p class="section-subtitle">各行各业，精彩纷呈</p>
    </div>
  </div>

  <section id="organizations" class="section video-section character-bg-img2">
    <video class="section-video" autoplay muted loop playsinline>
      <source src="https://s3plus.meituan.net/opapisdk/op_ticket_885190757_1757106279712_qdqqd_lf6cky.mp4" type="video/mp4">
    </video>
    <div class="section-overlay"></div>
    <div class="container">
      <div class="org-carousel-wrapper">
        <button class="carousel-btn left" @click="prevOrgCard()">
          <img src="https://www.yysls.cn/pc/fab/20250723194326/img/feature_prev_d3634779.png?image_process=format,png" alt="左箭头" style="width:70px;">
        </button>
        <div class="org-carousel">
          <div v-for="(org, index) in organizations" :key="org.id" :data-org="org.id" class="org-card-img">
            <div class="org-image">
              <img :src="org.image" :alt="org.name">
            </div>
            <div class="org-content">
              <h3>{{ org.name }}</h3>
              <p>{{ org.description }}</p>
              <div class="org-stats">
                <span>主持：{{ org.host }}</span>
                <span>时间：{{ org.time }}</span>
                <span>地点：{{ org.location }}</span>
              </div>
            </div>
          </div>
        </div>
        <button class="carousel-btn right" @click="nextOrgCard()">
          <img src="https://www.yysls.cn/pc/fab/20250723194326/img/feature_next_6f404b40.png?image_process=format,png" alt="右箭头" style="width:70px;">
        </button>
      </div>
    </div>
  </section>
</template>

<style scoped>
/* 百业活动区域右移 */
#organizations .container {
  margin-left: 100px; /* 可调整数值 */
}

/* 视频区域间距 */
.video-section-spacer {
  height: 250px;
  min-width: 1920px;
  width: 100vw;
  background: transparent;
  background-color: #1A202C;
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center; /* 水平居中 */
}

/* 视频背景区域 */
.video-section {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 1080px;
  min-width: 1920px;
  width: 100vw;
  height: 100vh;
}

.section-video {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  min-height: 1080px;
  object-fit: cover;
  z-index: 1;
  opacity: 1;
  transition: opacity 0.5s ease-in;
}

.section-overlay {
  position: absolute;
  top: 0;
  left: 0;
  min-height: 1080px;
  min-width: 1920px;
  width: 100vw;
  height: 100vh;
  background: linear-gradient(135deg, rgba(154, 103, 211, 0.3) 10%, rgba(0, 0, 0, 0.5) 100%);
  z-index: 2;
}

.video-section .container {
  position: relative;
  z-index: 3;
}

.section-header {
  text-align: center;
  margin-top: 0px;
}

.section-title {
  font-size: 3rem;
  font-weight: 700;
  margin-bottom: 15px;
  color: #2D3748;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
  position: relative;
}

.section-title::after {
  content: '';
  position: absolute;
  bottom: -10px;
  left: 50%;
  transform: translateX(-50%);
  width: 60px;
  height: 3px;
  background: linear-gradient(90deg, #2D3748, #4A5568);
  border-radius: 2px;
}

.section-subtitle {
  font-size: 1.2rem;
  color: #718096;
  font-weight: 300;
}

.org-image {
  height: 720px;
  position: relative;
}

.org-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s ease;
}

.org-content {
  height: 320px;
  width: 750px;
}

.org-content h3 {
  font-size: 2.5rem;
  font-weight: 600;
  margin-bottom: 10px;
  color: #b7c3da;
}

.org-content p {
  color: #718096;
  font-size: 1.5rem;
  margin-bottom: 20px;
  line-height: 1.6;
}

.org-stats {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 20px;
}

.org-stats span {
  background: #b7c3da;
  color: #2d384b;
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 0.9rem;
  font-weight: 500;
}

.btn-details {
  background: linear-gradient(135deg, #2D3748, #4A5568);
  color: #F7FAFC;
  border: none;
  padding: 10px 20px;
  border-radius: 25px;
  cursor: pointer;
  transition: all 0.3s ease;
  font-weight: 500;
}

.btn-details:hover {
  transform: translateY(-2px);
  box-shadow: 0 5px 15px rgba(45, 55, 72, 0.3);
}

.org-carousel-wrapper {
  display: flex;
  align-items: center;
  /* justify-content: center; */
  gap: 20px;
}

.carousel-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 10px;
  transition: transform 0.3s ease;
}

.carousel-btn:hover {
  transform: scale(1.1);
}

.org-card-img {
  background: linear-gradient(135deg, rgb(189, 131, 255,0.3) 0%, rgb(0, 0, 0,1) 100%);
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 1);
  transition: all 0.3s ease;
  border: linear-gradient(135deg, rgb(189, 131, 255) 0%, rgb(0, 0, 0) 100%);
  backdrop-filter: blur(10px);
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 1280px;
  min-height: 1000px;
  padding: 20px;
}
</style>